package com.yinhe.music.yhmusic.adapter;

import android.graphics.Color;
import android.widget.ImageView;

import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.yinhe.music.common.GlideHelper.GlideHelper;
import com.yinhe.music.common.utils.KeywordUtil;
import com.yinhe.music.yhmusic.R;
import com.yinhe.music.yhmusic.model.AlbumInfo;

/**
 * @author hasee
 * @date 2017/8/15
 */

public class AlbumAdapter extends BaseMultiItemQuickAdapter<AlbumInfo, BaseViewHolder> {
    private String key;

    public AlbumAdapter() {
        super(null);
        addItemType(AlbumInfo.OTHER_ALBUM_LSIT, R.layout.fav_album_item);
        addItemType(AlbumInfo.NEW_ALBUM_LSIT, R.layout.ablum_item);
    }

    public AlbumAdapter(String key) {
        super(null);
        this.key = key;
        addItemType(AlbumInfo.OTHER_ALBUM_LSIT, R.layout.fav_album_item);
        addItemType(AlbumInfo.NEW_ALBUM_LSIT, R.layout.ablum_item);
    }

    public void setSearchKey(String key) {
        this.key = key;
    }

    @Override
    protected void convert(BaseViewHolder helper, AlbumInfo item) {
        switch (helper.getItemViewType()) {
            case AlbumInfo.OTHER_ALBUM_LSIT:
                helper.setText(R.id.album_name, item.getAlbumName())
                        .setText(R.id.album_num, item.getSingerName());
                ImageView image = helper.getView(R.id.album_image);
                GlideHelper.setImageResource(image, item.getImage(), R.drawable.default_cover);
                if (key != null) {
                    helper.setText(R.id.album_name, KeywordUtil.matcherSearchTitle(Color.parseColor("#1d89ff"), item.getAlbumName(), key));
                    helper.setText(R.id.album_num, KeywordUtil.matcherSearchTitle(Color.parseColor("#1d89ff"), item.getSingerName(), key));
                }
                break;
            case AlbumInfo.NEW_ALBUM_LSIT:
                ImageView albumImage = helper.getView(R.id.new_album_pic);
                GlideHelper.setImageResource(albumImage, item.getImage(), R.drawable.default_cover);
                helper.setText(R.id.new_album_name, item.getAlbumName())
                        .setText(R.id.new_album_artist, item.getSingerName())
                        .setText(R.id.new_album_count, String.valueOf(item.getCollectNum()));
                break;
        }

    }
}
